package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.EatShowUserInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by Administrater on 2015/12/8.
 */
public class ThirdLoginTask extends CouponHttpBaseTask {

    private String mOpenId;
    private String mUserLogo;
    private String mNickName;
    private String mSystem;
    private String mAreaName;
    private String mChannel;
    private int thirdType;

    public ThirdLoginTask(String openId,String nickName,String userLogo,String generalizeChannel,int type) {
        super(TaskType.THIRD_LOGIN_TASK);
        mOpenId = openId;
        mNickName = nickName;
        mUserLogo = userLogo;
//        mSystem = system;
//        mAreaName =areaName;
        mChannel = generalizeChannel;
        thirdType = type;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        {
            JSONObject json = response.getBody();
            EatShowUserInfo userInfo = null;
            if (json != null) {
                userInfo = JSON.parseObject(json.toString(), EatShowUserInfo.class);
            }
            notifyTaskCompleted(TaskResultCode.SUCCESS, userInfo);
        }
    }

    @Override
    protected void prepareRequest() {
        {
            super.prepareRequest();
            if (mPhase == TASK_PHASE_INIT) {
                CouponHttpRequest request = new CouponHttpRequest(RequestType.THIRD_LOGIN_REQUEST);
                JSONObject jsonData = new JSONObject();
                jsonData.put("openId", mOpenId);
                jsonData.put("nickName",mNickName);
                jsonData.put("userLogo",mUserLogo);
//                jsonData.put("system",mSystem);
//                jsonData.put("areaName",mAreaName);
                jsonData.put("generalizeChannel",mChannel);
                jsonData.put("thirdType",thirdType);
                request.setData(jsonData.toString());
                request.setApiNo(ApiNo.THIRD_LOGIN);
                addRequest(request);
            }
        }
    }
}
